--- permalink: python/heatmap-webgl/ description: How to make webGL based heatmaps in Python with Plotly. name: WebGL based Heatmaps | plotly has_thumbnail: true thumbnail: thumbnail/heatmap-webgl.jpg layout: user-guide name: WebGL Heatmaps language: python title: Python Heatmaps WebGL | plotly display_as: scientific has_thumbnail: true page_type: example_index order: 4 --- {% raw %}
We start by importing the relevant modules:
import plotly.offline as py
# py.init_notebook_mode()
import PIL
import urllib, cStringIO
import numpy as np
image_url = 'https://s-media-cache-ak0.pinimg.com/736x/26/63/9a/26639a3cf8d30c21a9a2ca65695712d9.jpg'
f = cStringIO.StringIO(urllib.urlopen(image_url).read())
img = PIL.Image.open(f)
img
arr = np.array(img)
z_data = []
for i in range(500):
k = []
for j in range(500):
k.append(sum(arr[i][j]))
z_data.append(k)
trace = dict(type='heatmapgl', z=z_data)
py.iplot([trace], validate=False)